//
//  News.swift
//  oschina
//
//  Created by 林村 on 15/5/14.
//  Copyright (c) 2015年 林村. All rights reserved.
//

class News: NSObject {

    var id:Int?
    var title:String?
    var body:String?
    var commentCount:Int = 0
    var author:String?
    var authorid:Int?
    var pubDate:String?
    var url:String?
    
    
   
    
    static func parserList(xmlContent:String) ->[News] {
        let xml = SWXMLHash.parse(xmlContent)
        var list = [News]()
        
        var listX = xml["oschina"]["newslist"]
        var count:Int! = 0
        count = listX.element?.count
        for i in 0...count-1 {
            
            var newXml = listX["news"][i]
            var news = News()
                
            news.id = (newXml["id"].element?.text) as? Int
            news.title = newXml["title"].element?.text
            news.body = newXml["body"].element?.text
            
            if var c = newXml["commentCount"].element?.text {
                news.commentCount = c.toInt()!
            }
            
            news.pubDate = newXml["pubDate"].element?.text
            
            
            list.append(news)
            
        }
    
        return list
    }
}
